#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using ll = long long;
bool isPrime(int n)
{
    if (n < 2)
        return false;
    for (long long i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
            return false;
    }
    return true;
}

void solve()
{
    int x, k;
    cin >> x >> k;
    if (k == 1)
    {
        cout << (isPrime(x) ? "YES" : "NO") << "\n";
    }
    else
    {
        if (x != 1)
        {
            cout << "NO\n";
        }
        else
        {
            cout << (k == 2 ? "YES" : "NO") << "\n";
        }
    }
}

int main()
{
    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
   return 0;
}
